package com.stormrage.edu.dao.learn.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.learn.LeaTermDao;
import com.stormrage.entity.learn.LeaTerm;
import com.stormrage.entity.learn.rep.LeaTermRep;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: LeaTermDaoImpl.java
 * @Package com.stormrage.edu.dao.learn.impl
 * @Description: 学期 Dao
 * @author www.stormragetech.com
 * @date 2016年4月13日
 * @version V1.0
 */
@Repository
public class LeaTermDaoImpl extends MysBaseDao implements LeaTermDao {

	private static final Logger logger = LoggerFactory.getLogger(LeaTermDaoImpl.class);

	public LeaTerm queryById(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 LeaTermDao 】- 【 QueryById 】- 开始运行 ");

		final String query = "SELECT * FROM lea_term WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		LeaTerm entity = queryObject(query, LeaTerm.class, map);

		logger.debug(" 【 Dao 】- 【 LeaTermDao 】- 【 QueryById 】- 完成运行 ");
		return entity;

	}

	public List<LeaTermRep> queryList() throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 LeaTermDao 】- 【 QueryList 】- 开始运行 ");

		final String query = "SELECT a.id, a.term, a.apply_date_start, a.study_date_start, a.exam_date_start, b.major"
				+ " FROM lea_term AS a, edu_major AS b WHERE a.major_id = b.id AND a.apply_date_start < now()";
		logger.debug(" 数据库执行语句为 " + query);

		List<LeaTermRep> array = queryList(query, LeaTermRep.class);

		logger.debug(" 【 Dao 】- 【 LeaTermDao 】- 【 QueryList 】- 完成运行 ");
		return array;

	}

}
